<!DOCTYPE html>
<html lang="en">
<head>
	<include data="head.html">
	<title>{$title}</title>
</head>
<body data-menu="users">
	<div class="container">
		<if data="empty($_GET['user_id']) && empty($_GET['action'])">
			<!-- 用户列表 -->
			<ul class="nav nav-tabs" role="tablist" id="user-list-tabs">
				<li role="presentation">
					<a href="javascript:;">所有({$userCount['all']})</a>
				</li>
				<li role="presentation">
					<a href="javascript:;" data-level="5">管理员({$userCount['admin']})</a>
				</li>
				<li role="presentation">
					<a href="javascript:;" data-level="4">编辑({$userCount['editor']})</a>
				</li>
				<li role="presentation">
					<a href="users.html?action=add">新建</a>
				</li>
			</ul>
			<div class="table-responsive">
				<table class="table table-hover" id="user-list-table">
					<thead>
						<tr>
							<th>#</th>
							<th>用户名</th>
							<th>昵称</th>
							<th>性别</th>
							<th>电子邮箱</th>
						</tr>
					</thead>
					<tbody>
						{!$id = 1}
						<while data="get_multi_user()">
							<tr data-id="{user_id()}">
								<td>{$id++}</td>
								<td>
									<a title="查看" href="users.html?user_id={user_id()}">
										{user_name()}
									</a>
								</td>
								<td>{user_nickname()}</td>
								<td>{@$userGender[user_gender()]}</td>
								<td>{user_email()}</td>
							</tr>
						</while>
					</tbody>
				</table>
			</div>
			<if data="is_admin()">
				<div class="modal fade" id="change-level-modal">
					<div class="modal-dialog modal-sm">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
								<h4 class="modal-title">选择用户组</h4>
							</div>
							<div class="modal-body">
								<select name="user_level" id="user_level">
									<foreach data="$userLevel as $k => $v">
										<if data="$k == 5 && me_id() != 1 || $k == 0">
											<continue>
										</if>
										<option value="{$k}"{user_level() == $k ? ' selected' : ''}>
											{$v}
										</option>
									</foreach>
								</select>
							</div>
							<div class="modal-footer">
								<button type="submit" class="btn btn-success">保存</button>
							</div>
						</div>
					</div>
				</div>
			</if>
			<elseif data="!empty($_GET['action'])">
				<!-- 用户编辑页面 -->
				<ul class="nav nav-tabs" role="tablist" id="user-edit-tabs">
					<li role="presentation" class="active">
						<a href="javascript:;" data-id="set-basic">基本信息</a>
					</li>
					<li role="presentation">
						<a href="javascript:;" data-id="set-avatar">头像</a>
					</li>
					<li role="presentation">
						<a href="javascript:;" data-id="set-protection">隐私</a>
					</li>
				</ul>
				<form action="{site_url()}mod.php?user::{$_GET['action']}" method="post" role="from" id="user-edit-form">
					<if data="$_GET['action'] == 'update'">
						<input type="hidden" name="user_id" value="{user_id()}">
					</if>
					<button type="submit">提交</button>
					<table id="set-basic" class="table table-hover user-edit-table">
						<tbody>
							<tr>
								<td><label for="user_name">用户名</label></td>
								<td><input type="text" id="user_name" name="user_name" placeholder="用于登录站点" value="{user_name()}"></td>
							</tr>
							<tr>
								<td><label for="user_nickname">昵称</label></td>
								<td><input type="text" id="user_nickname" name="user_nickname" placeholder="用户的主显示名称" value="{user_nickname()}"></td>
							</tr>
							<tr>
								<td><label for="user_gender">性别</label></td>
								<td>
									<foreach data="$userGender as $k => $v">
										<label class="radio-inline">
											<input type="radio" name="user_gender" value="{$k}"{user_gender() == $k ? ' checked' : ''} />{$v}
										</label>
									</foreach>
								</td>
							</tr>
							<tr>
								<td><label for="user_realname">真实姓名</label></td>
								<td><input type="text" id="user_realname" name="user_realname" placeholder="{$person}真实的姓名" value="{user_realname()}"></td>
							</tr>
							<tr>
								<td><label for="user_identity">身份</label></td>
								<td><input type="text" id="user_identity" name="user_identity" placeholder="现实生活中{$person}的身份" value="{user_identity()}"></td>
							</tr>
							<tr>
								<td><label for="user_company">工作单位</label></td>
								<td><input type="text" id="user_company" name="user_company" placeholder="{$person}所工作的地方" value="{user_company()}"></td>
							</tr>
							<tr>
								<td><label for="user_number">身份编号</label></td>
								<td><input type="text" id="user_number" name="user_number" placeholder="{$person}的学号、工号或身份证号码等" value="{user_number()}"></td>
							</tr>
							<tr>
								<td><label for="user_email">电子邮箱</label></td>
								<td><input type="email" id="user_email" name="user_email" placeholder="用于接收邮件、辅助登录等" value="{user_email()}"></td>
							</tr>
							<tr>
								<td><label for="user_tel">手机号码</label></td>
								<td><input type="tel" id="user_tel" name="user_tel" placeholder="用于接收短信、辅助登录等" value="{user_tel()}"></td>
							</tr>
							<tr>
								<td><label for="user_desc">用户简介</label></td>
								<td><textarea name="user_desc" id="user_desc" rows="2" placeholder="简单地描述{$person}">{user_desc()}</textarea></td>
							</tr>
							<if data="is_admin() && user_id() != me_id()">
								<tr>
									<td><label for="user_level">用户组</label></td>
									<td>
										<select name="user_level" id="user_level">
											<foreach data="$userLevel as $k => $v">
												<if data="$k == 5 && me_id() != 1 || $k == 0">
													<continue>
												</if>
												<option value="{$k}"{user_level() == $k ? ' selected' : ''}>
													{$v}
												</option>
											</foreach>
										</select>
									</td>
								</tr>
							</if>
						</tbody>
					</table>
					<div id="set-avatar">
						<input type="hidden" name="user_avatar" value="{user_avatar()}">
						<h4>当前头像</h4>
						<img {user_avatar() == false ? 'style="display:none"' : ''}src="{get_user_avatar(128, user_avatar())}" data-origin="{get_user_avatar(128, user_avatar())}" alt="用户头像" id="user-avatar">
						<button type="button" class="btn btn-success" id="select-avatar" data-loading-text="打开文件...">选择图片</button>
					</div>
					<table id="set-protection" class="table table-hover user-edit-table">
						<tbody>
							<if data="me_id() == user_id()">
								<tr>
									<td><label for="old_password">原始密码</label></td>
									<td>
										<input type="text" id="old_password" name="old_password" placeholder="需要验证旧的密码">
										<if data="!is_agent('Edge/14')">
											<i class="glyphicon glyphicon-eye-open"></i>
										</if>
									</td>
								</tr>
							</if>
							<tr>
								<td><label for="user_password">新密码</label></td>
								<td>
									<input type="text" id="user_password" name="user_password" placeholder="不{$_GET['action'] == 'update' ? '修改' : '设置'}请留空">
									<if data="!is_agent('Edge/14')">
										<i class="glyphicon glyphicon-eye-open"></i>
									</if>
								</td>
							</tr>
							<tr>
								<td><label for="user_protect">仅{$person}可见的信息</label></td>
								<td>
									<select name="user_protect[]" id="user_protect" multiple>
										<foreach data="$userProtect as $k => $v">
											<option value="{$k}"{(user_protect() && in_array($k, user_protect())) ? ' selected' : ''}>
												{$v}
											</option>
										</foreach>
									</select>
								</td>
							</tr>
						</tbody>
					</table>
				</form>
			</elseif>
			<elseif data="get_user()">
				<!-- 用户个人中心页面 -->
				<div id="user-center">
					<div class="user-thumbnail">
					    <div class="user-avatar">
					    	<if data="user_avatar()">
					    		<img src="{get_user_avatar()}" alt="用户头像">
								<else>
									<i class="glyphicon glyphicon-user media-icon"></i>
								</else>
					    	</if>
					    </div>
					</div>
					<div class="user-display-name">
						<p>
							{user_nickname() ?: user_name()} 
							<small>({$userLevel[user_level()]})</small>
						</p>
					</div>
					<div class="user-desc">
						<p>{user_desc()}</p>
					</div>
					<div class="user-activities">
						<if data="(!in_array('posts.html', $privileges['admin']) || IS_ADMIN) && (!in_array('posts.html', $privileges['editor']) || IS_AUTH)">
							<div>
								<h4>
									{$person}的文章
									<if data="get_multi_post(array('user_id'=>user_id(), 'sequence'=>'desc'))">
										{!get_multi_post(0)}
										<if data="$_GET['user_id'] == ME_ID || IS_AUTH">
											<small>
												<a href="posts.html?user_id={user_id()}">更多 »</a>
											</small>
										</if>
									</if>
								</h4>
								<div class="activity-contents">
									<while data="get_multi_post()">
										<div>
											<h5>
												<a title="查看" target="_blank" href="{get_post_link()}" title="{post_title()}">
													{post_title()}
												</a>
												<small>{date('Y-m-d', post_time())}</small>
											</h5>
											<p>{get_post_desc(200)}</p>
										</div>
									</while>
								</div>
							</div>
						</if>
						<if data="(!in_array('comments.html', $privileges['admin']) || IS_ADMIN) && (!in_array('comments.html', $privileges['editor']) || IS_AUTH)">
							<div>
								<h4>
									{$person}的评论
									<if data="get_multi_comment(array('user_id'=>user_id(), 'sequence'=>'desc'))">
										{!get_multi_comment(0)}
										<if data="$_GET['user_id'] == ME_ID || IS_AUTH">
											<small>
												<a href="comments.html?user_id={user_id()}">更多 »</a>
											</small>
										</if>
									</if>
								</h4>
								<div class="activity-contents">
									<while data="get_multi_comment()">
										<div>
											<h5>
												{date('Y-m-d', comment_time())} 于 {comment_post('post_title')}
											</h5>
											<p>
												<if data="comment_parent()">
													<a title="查看此人的个人空间" href="users.html?user_id={comment_parent('user_id')}">
														@{comment_parent('user_nickname') ?: comment_parent('user_name')}
													</a>
												</if>
												{comment_content()}
											</p>
										</div>
									</while>
								</div>
							</div>
						</if>
					</div>
				</div>
			</elseif>
		</if>
	</div>
	<script>
		TOTAL = {_user('total') ?: 0};
		PAGES = {_user('pages') ?: 0};
	</script>
	<include data="foot.html">
</body>
</html>